/*
题目描述：

小a有x只羊和y只狼，现在，他需要通过一座桥。由于桥面很窄，桥每次只允许通过小a和n只动物。小a很爱动物，所以他每次通过桥时都必须有一只动物陪着他，否则他会很寂寞。并且不论是在墙上或者是在桥的两头，一旦羊的数量少于狼的数量，狼就会开始吃羊。为了不让羊被吃掉，又要让所有动物和小a自己都通过桥，小a至少要过桥多少次？

输入：

多组数据，每一组数据包含三个整数x, y, n(0≤?x, y, n?≤?200)。

输出：

对于每组数据，如果能顺利顺利过桥并且不损失一头羊，则输出需要的最少过桥次数。否则，输出 - 1。
*/


#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#if defined(_WIN32) && !defined(__cplusplus)
#define inline __inline
#endif

#include <stdio.h>
#include <malloc.h>
#include <memory.h>

#define min(a,b)    (((a) < (b)) ? (a) : (b))

typedef struct
{
	int SheepNum;
	int WolfNum;
}SideAnimals;

typedef struct
{
	SideAnimals LeftAnimals;
	SideAnimals RightAnimals;
	int StepNum;
}Animals;

#define MAX_ANIMAL_NUM 201
typedef unsigned char BYTE;
typedef Animals QElemType;
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
typedef int Status; /* Status是函数的类型,其值是函数结果状态代码，如OK等 */
typedef int BOOL; /* Boolean是布尔类型,其值是TRUE或FALSE */
/* 单链队列－－队列的链式存储结构 */
typedef struct QNode
{
	QElemType data;
	struct QNode *next;
}QNode, *QueuePtr;

typedef struct
{
	QueuePtr front, rear; /* 队头、队尾指针 */
}LinkQueue;

BYTE LeftSideAnimalsVisit[MAX_ANIMAL_NUM][MAX_ANIMAL_NUM];
BYTE RightSideAnimalsVisit[MAX_ANIMAL_NUM][MAX_ANIMAL_NUM];

Status InitQueue(LinkQueue *Q)
{ /* 构造一个空队列Q */
	Q->front = Q->rear = (QueuePtr)calloc(1, sizeof(QNode));
	if (!Q->front)
		return ERROR;
	Q->front->next = NULL;
	return OK;
}

Status DestroyQueue(LinkQueue *Q)
{ /* 销毁队列Q(无论空否均可) */
	while (Q->front)
	{
		Q->rear = Q->front->next;
		free(Q->front);
		Q->front = Q->rear;
	}
	return OK;
}

Status ClearQueue(LinkQueue *Q)
{ /* 将Q清为空队列 */
	QueuePtr p, q;
	Q->rear = Q->front;
	p = Q->front->next;
	Q->front->next = NULL;
	while (p)
	{
		q = p;
		p = p->next;
		free(q);
	}
	return OK;
}

BOOL IsQueueEmpty(const LinkQueue *Q)
{ /* 若Q为空队列,则返回TRUE,否则返回FALSE */
	return Q->front == Q->rear;
}

Status EnQueue(LinkQueue *Q, QElemType e)
{ /* 插入元素e为Q的新的队尾元素 */
	QueuePtr p = (QueuePtr)malloc(sizeof(QNode));
	if (!p) /* 存储分配失败 */
		return ERROR;
	p->data = e;
	p->next = NULL;
	Q->rear->next = p;
	Q->rear = p;
	return OK;
}

Status DeQueue(LinkQueue *Q, QElemType *e)
{ /* 若队列不空,删除Q的队头元素,用e返回其值,并返回OK,否则返回ERROR */
	QueuePtr p;
	if (Q->front == Q->rear)
		return ERROR;
	p = Q->front->next;
	*e = p->data;
	Q->front->next = p->next;
	if (Q->rear == p)
		Q->rear = Q->front;
	free(p);
	return OK;
}

inline BOOL IsAnimalsAtLeft(const Animals *animals)
{
	return animals->StepNum % 2 == 0;
}

inline BOOL IsSideAnimalsSafe(const SideAnimals *sideAnimals)
{
	if (sideAnimals->SheepNum == 0) return TRUE;
	if (sideAnimals->SheepNum >= sideAnimals->WolfNum) return TRUE;
	return FALSE;
}

inline BOOL IsAnimalsSafe(const Animals *animals)
{
	return IsSideAnimalsSafe(&animals->LeftAnimals)
		&& IsSideAnimalsSafe(&animals->RightAnimals);
}

inline BOOL CanMoveFromSide(const SideAnimals *sourceSideAnimals, int sheepNum, int wolfNum)
{
	return sourceSideAnimals->SheepNum >= sheepNum && sourceSideAnimals->WolfNum >= wolfNum;
}

inline BOOL IsVisited(const Animals *sourceAnimals, BOOL isLeftSide)
{
	if (isLeftSide) return LeftSideAnimalsVisit[sourceAnimals->LeftAnimals.SheepNum][sourceAnimals->LeftAnimals.WolfNum] != 0;
	else return RightSideAnimalsVisit[sourceAnimals->RightAnimals.SheepNum][sourceAnimals->RightAnimals.WolfNum] != 0;
}

inline void SetVisited(const Animals *sourceAnimals, BOOL isLeftSide)
{
	if (isLeftSide) LeftSideAnimalsVisit[sourceAnimals->LeftAnimals.SheepNum][sourceAnimals->LeftAnimals.WolfNum] = 1;
	else RightSideAnimalsVisit[sourceAnimals->RightAnimals.SheepNum][sourceAnimals->RightAnimals.WolfNum] = 1;
}

BOOL CanMove(const Animals *sourceAnimals, int sheepNum, int wolfNum, BOOL isFromLeftSide)
{
	if (isFromLeftSide) return CanMoveFromSide(&sourceAnimals->LeftAnimals, sheepNum, wolfNum);
	else return CanMoveFromSide(&sourceAnimals->RightAnimals, sheepNum, wolfNum);
}

Animals MoveAnimals(const Animals *sourceAnimals, int sheepNum, int wolfNum, BOOL isFromLeftSide)
{
	if (isFromLeftSide)
	{
		Animals tempAnimals = {
			{sourceAnimals->LeftAnimals.SheepNum - sheepNum,
			sourceAnimals->LeftAnimals.WolfNum - wolfNum},
			{sourceAnimals->RightAnimals.SheepNum + sheepNum,
			sourceAnimals->RightAnimals.WolfNum + wolfNum},
			sourceAnimals->StepNum + 1
		};
		return tempAnimals;
	}
	else
	{
		Animals tempAnimals = {
			{sourceAnimals->LeftAnimals.SheepNum + sheepNum,
			sourceAnimals->LeftAnimals.WolfNum + wolfNum},
			{sourceAnimals->RightAnimals.SheepNum - sheepNum,
			sourceAnimals->RightAnimals.WolfNum - wolfNum},
			sourceAnimals->StepNum + 1
		};
		return tempAnimals;
	}
}

// 有x只羊和y只狼，桥每次只允许通过n只动物
int CrossBridge(int x, int y, int n)
{
	LinkQueue queue;
	InitQueue(&queue);
	int result = -1;

	Animals startAnimals = {{x, y}, {0, 0}, 0};
	EnQueue(&queue, startAnimals);
	while (!IsQueueEmpty(&queue))
	{
		Animals animals;
		DeQueue(&queue, &animals);
		if (animals.LeftAnimals.SheepNum == 0 && animals.LeftAnimals.WolfNum == 0)
		{
			result = animals.StepNum;
			goto end;
		}

		BOOL isLeft = IsAnimalsAtLeft(&animals);
		for (int i = 0; i <= min(x, n); i++)
		{
			for (int j = 0; j <= min(y, n); j++)
			{
				if (i + j > n || (i == 0 && j == 0)) continue;
				if (i == 0 || i >= j)
				{
					if (CanMove(&animals, i, j, isLeft))
					{
						Animals tempAnimals = MoveAnimals(&animals, i, j, isLeft);
						if (IsAnimalsSafe(&tempAnimals) && !IsVisited(&tempAnimals, isLeft))
						{
							EnQueue(&queue, tempAnimals);
							SetVisited(&tempAnimals, isLeft);
						}
					}
				}
			}
		}
	}

end:
	DestroyQueue(&queue);
	return result;
}

int main()
{
	int num;
	scanf("%d", &num);

	for (int i = 0; i < num; i++)
	{
		memset(LeftSideAnimalsVisit, 0, sizeof(BYTE) * MAX_ANIMAL_NUM * MAX_ANIMAL_NUM);
		memset(RightSideAnimalsVisit, 0, sizeof(BYTE) * MAX_ANIMAL_NUM * MAX_ANIMAL_NUM);
		int x, y, n;
		scanf("%d%d%d", &x, &y, &n);
		int result = CrossBridge(x, y, n);
		printf("%d\n", result);
	}
}
